package socket;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class Server01 {
        private ServerSocket serverSocket;

    public Server01() {
        try {

            serverSocket=new ServerSocket(8089);
            System.out.println("等待连接...");
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
    public void start(){
        try {
            Socket socket = serverSocket.accept();
            System.out.println("一个客户端已连接。");

            InputStream is = socket.getInputStream();
            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);


            String str;
            System.out.println("客户端说：");
            while((str=br.readLine())!=null){
                System.out.println(str);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    public static void main(String[] args) {
        Server01 server01 = new Server01();
        server01.start();
    }
}
